package sii.fb.emotion.computProbability;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import sii.fb.emotion.Main;
import sii.fb.emotion.bean.Post;

public class ProbabilityBasedOnTime {

	//Probability of occurrences of emotions in status updates depending on the day of the week and the month of the year.
		public void dayAndMonth2Emotion(Map<Long, List<Post>> posts){
			SupportMethod cp = new SupportMethod();
			Map<Integer, Float[]> daysEmotion = new HashMap<Integer, Float[]>();
			Map<Integer, Float[]> monthEmotion = new HashMap<Integer, Float[]>();
			int[] days = new int[7];
			int[] months = new int[12];
			for(Long l:posts.keySet()){
				List<Post> post = posts.get(l);
				for(Post p: post){
					Date time = p.getUpdate();
					if(time!=null){
						String day = new SimpleDateFormat("E").format(time);
						int d = defineDay(day);
						int month = Integer.parseInt(new SimpleDateFormat("MM").format(time));
						float[] emotionPost = p.getEmotion();
						if(d>0){
						if(daysEmotion.get(d)!=null){
							cp.updateEmotionArray(emotionPost, daysEmotion.get(d)); //update map of days
						}else{
							daysEmotion.put(d, new Float[]{0F,0F,0F,0F,0F,0F,0F,0F,0F,0F,0F});
							cp.updateEmotionArray(emotionPost, daysEmotion.get(d)); //update map of days
						}
						days[d-1]++;
						}
						if(monthEmotion.get(month)!=null){
							cp.updateEmotionArray(emotionPost, monthEmotion.get(month)); //update map of months
						}else{
							monthEmotion.put(month, new Float[]{0F,0F,0F,0F,0F,0F,0F,0F,0F,0F,0F});
							cp.updateEmotionArray(emotionPost, monthEmotion.get(month)); //update map of months
						}
						months[month-1]++;
					}
				}
			}
			Main.print += "----------TIME----------\n";
			Main.print += "----------DAYS----------\n";
			for (Integer i: daysEmotion.keySet()){
				cp.normalizeListPostEm(daysEmotion.get(i), days[i-1]);
			}
			Main.print += "----------MONTHs----------\n";

			for (Integer i: monthEmotion.keySet()){
				cp.normalizeListPostEm(monthEmotion.get(i), months[i-1]);
			}
		}
		
		

		
		private int defineDay(String day) {
			if(day.equals("lun")) return 1;
			if(day.equals("mar")) return 2;
			if(day.equals("mer")) return 3;
			if(day.equals("gio")) return 4;
			if(day.equals("ven")) return 5;
			if(day.equals("sab")) return 6;
			if(day.equals("dom")) return 7;
			return -1;
		}
		
}
